﻿/**
 * Player.cs - Character controlled by the player
 * 
 * Part of BoulderDAM - A BoulderDash clone using C# and SDL
 * Nacho Cabanes & students of DAM IES San Vicente, 2014
 * 
 * Revisions
 * #     Date         Creator, changes
 * ----  -----------  -------------------------------------------------------
 * 0.01  02-apr-2014  Nacho Cabanes: basic skeleton: loads sequence and moves
 *                        right and left
 * 0.02  04-apr-2014  Álvaro Gironés, Cristóbal Sánchez, Juan Carlos Gallardo:
 *                      images for player movement in all directions, methods
 *                      for movement in every direction filled. 
 *                      Getters and setters.
 *                      Method for losing lives and death.
 *                      Restart method overriden to be able to restart lives.
 * 0.04 07-APR-2014   Marco Uceda, Cristóbal Sánchez, David Caamaño:
 *                      The sprites now move slowlier
 *                      
 */
namespace Boulder

{
    class Player : Sprite
    {
        int lives;
        int stepCount;

        public Player()
        {
            LoadSequence(RIGHT, new string[] { "data/playerR01.png", "data/playerR02.png", "data/playerR03.png" });
            LoadSequence(LEFT, new string[] { "data/playerL01.png", "data/playerL02.png", "data/playerL03.png" });
            LoadSequence(DOWN, new string[] { "data/playerF01.png", "data/playerF02.png" });
            LoadSequence(UP, new string[] { "data/playerF01.png", "data/playerF02.png" });
            MoveTo(300, 300);
            xSpeed = 4;
            ySpeed = 4;
            lives = 5;
        }

        public void MoveRight()
        {
            ChangeDirection(RIGHT);
            x += xSpeed;
            CheckFrame();
        }

        public void MoveLeft()
        {
            ChangeDirection(LEFT);
            x -= xSpeed;
            CheckFrame();
        }

        public void MoveUp()
        {
            ChangeDirection(UP);
            y -= ySpeed;
            //CheckFrame();
        }

        public void MoveDown()
        {
            ChangeDirection(DOWN);
            y += ySpeed;
            //CheckFrame();
        }

        public void CheckFrame()
        {
            if (stepCount % 5 == 0)
                NextFrame();
            stepCount++;

            if (stepCount > 5)
                stepCount = 1;
        }

        public bool IsDead()
        {
            return false;
        }

        public int GetLives()
        {
            return lives;
        }

        public void SetLives(int lives)
        {
            this.lives = lives; 
        }

        public int LoseLife()
        {
            return lives - 1; 
        }

        public override void Restart()
        {
            base.Restart();
            lives = 5;
        }
    }
}
